<extend name="Bt/register_back_base"/>

<block name="content">
    <div class="context" style="position: relative;height:900px">
        <div class="ctPdding ">
            <div class="ct_header"><i></i>用户注册</div>
            <hr />
            <div class="regContainer">
                <div class="regItme">
                    <ul>
                        <li class="itmeBorder">
                            <span class="regLogo">1</span>
                            <span class="color6">填写账户信息</span>
                        </li>
                        <li class="itmeTwo">
                            <span class="noRegLogo">2</span>
                            <span class="color6">激活账户</span>
                        </li>
                        <li>
                            <span class="noRegLogo">3</span>
                            <span class="color6">完成</span>
                        </li>
                    </ul>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="regGroupContainer">
                <form action="{:U('register')}" method="post" class="registerForm">
                    <input id="name" class="userStyle tooltipBtn" type="hidden" name="role" value="{$role_list[0]['id']}">
                    <div class="userContainer marginTop50 marginBottom20">
                        <input type="hidden" name="reg_type" value="email"  <if condition='$key neq 0'>disabled="disabled"</if>>
                        <input type="hidden" id="nickname"  name="nickname">
                        <input type="text" id="email" class="userStyle tooltipBtn" check-type="UserEmail" check-url="{:U('ucenter/member/checkAccount')}" <if condition='$key neq 0'>disabled="disabled"</if>
                        placeholder="{:L('_PLACEHOLDER_EMAIL_INPUT_')}" value="" name="username">
                        <img class="userMsg" src="__IMG__/bt/err_small_a1085c53.png" style="display: none"/>
                        <span class="size12 colorRed" style="display: none"></span>
                        <div class="userLogo"><img src="__IMG__/bt/user/user.png"/></div>
                        <div class="regTooltipFour tool">
                            <div class="tooltips toolFourW">
                                <span class="msg">此邮箱作为登录账号</span>
                            </div>
                            <div class="arrows toolKey regLeft"></div>
                        </div>
                    </div>
                    <div class="userContainer marginBottom20">
                        <input type="password" id="inputPassword" class="userStyle tooltipBtn" check-length="6,30"  placeholder="请输入密码"  name="password">
                        <img class="userMsg" src="__IMG__/bt/err_small_a1085c53.png" style="display: none"/>
                        <span class="size12 colorRed" style="display: none"></span>
                        <div class="userLogo"><img src="__IMG__/bt/user/userlogo.png"/></div>
                        <div class="regTooltipPwd tool">
                            <div class="tooltips toolFourW">
                                <div class="arrows toolKey regLeftPwd"></div>
                                <span class="msg">长度为6～30个字符 支持数字，大小写字母与标点符号 不允许有空格</span>
                            </div>
                        </div>
                    </div>
                    <div class="userContainer marginBottom20">
                        <input class="userStyle" type="password" placeholder="请再次输入密码" id="inputPassword2"/>
                        <img class="userMsg" src="__IMG__/bt/err_small_a1085c53.png" style="display: none"/>
                        <span class="size12 colorRed" style="display: none"></span>
                        <div class="userLogo"><img src="__IMG__/bt/user/userlogo.png"/></div>
                    </div>
                    <div class="userContainer marginBottom20">
                        <div class="userLogoBtn stratHover">下一步</div>
                    </div>
                    <div class="userContainer marginBottom20">
                        <div class="regAgree color3">
                            <img style="vertical-align: middle;" src="__IMG__/bt/user/userok.png"/>
                            <label>我同意</label>
                            <a href="{:U('Ucenter/Member/userhelp')}" class="color00" target="_blank">《邦兔用户协议》</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</block>

<block name="javascriptPageLevelPlugins">
    <script src="__JS__/bt/plugins/md5/md5.js" type="text/javascript" charset="utf-8"></script>
</block>

<block name="javascriptPageLeveCode">
    <script type="text/javascript">
        $(function(){
            //提交
            var step="{$step}";

            var self = $('form');

            if (MID == 0 && step=='start') {
                //提交
                $('.userLogoBtn').on('click',function(){
                    $('.userMsg').hide();
                    $('.colorRed').hide();
                    var inputPassword = $('#inputPassword').val();
                    var inputPassword2 = $('#inputPassword2').val();
                    if(inputPassword != inputPassword2){
                        $('#inputPassword').nextAll('.userMsg').show();
                        $('#inputPassword').nextAll('.colorRed').text('两次输入的密码不一样~！').show();
                        $('#inputPassword2').nextAll('.userMsg').show();
                        $('#inputPassword2').nextAll('.colorRed').text('两次输入的密码不一样~！').show();
                        return false;
                    }
                    $.post(self.attr("action"), self.serialize(), function(data){
                        if (data.status) {
                            setTimeout(function () {
                                window.location.href = data.url
                            }, 10);
                        } else {
                            if(data.info.indexOf("密") >= 0){
                                $('#inputPassword').nextAll('.userMsg').show();
                                $('#inputPassword').nextAll('.colorRed').text(data.info).show();
                                return false;
                            }
                            $('#email').nextAll('.userMsg').show();
                            $('#email').nextAll('.colorRed').text(data.info).show();
                        }
                    }, "json");
                });

                //光标 失去焦点
                $('.registerForm').on('blur','input[type!=hidden]',function(){

                    $('.userMsg').hide();

                    $('.colorRed').hide();

                    var email = $('#email').val();

                    var inputPassword = $('#inputPassword').val();

                    var inputPassword2 = $('#inputPassword2').val();

                    if(!email){
                        $('#email').focus();
                        $('#email').nextAll('.userMsg').show();
                        $('#email').nextAll('.colorRed').text('请输入您要注册的邮箱').show();
                        return false;
                    }else{
                        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
                        var status = 1;
                        if (!reg.test(email)) {
                            $('#email').focus();
                            $('#email').nextAll('.userMsg').show();
                            $('#email').nextAll('.colorRed').text('邮箱格式不正确，请重新填写!').show();
                            return false;
                        }
                        $.ajax({
                            url:'/index.php?s=/ucenter/member/isUserEmail',
                            type:'post',
                            data:'email='+email,
                            async: false,
                            success:function(data){
                                if(data.status == 0){
                                    status = 0;
                                }
                            },
                            dataType:'json'
                        });
                        if(status==0){
                            $('#email').focus();
                            $('#email').nextAll('.userMsg').show();
                            $('#email').nextAll('.colorRed').text('帐号已被使用').show();
                            return false;
                        }
                    }

                    if(!inputPassword){
//                        $('#inputPassword').focus();
                        $('#inputPassword').nextAll('.userMsg').show();
                        $('#inputPassword').nextAll('.colorRed').text('请输入密码').show();
                        return false;
                    }else{
                        if(!(inputPassword.length <= 30 && inputPassword.length>=6)){
                            $('#inputPassword').nextAll('.userMsg').show();
                            $('#inputPassword').nextAll('.colorRed').text('密码长度必须在6-30个字符之间 !').show();
                            return false;
                        }
                        var _reg = /^[\S]*$/;
                        if(!_reg.test(inputPassword)){
                            $('#inputPassword').nextAll('.userMsg').show();
                            $('#inputPassword').nextAll('.colorRed').text('密码不能含有空格 !').show();
                            return false;
                        }

                        if(inputPassword != inputPassword2){
                            $('#inputPassword').nextAll('.userMsg').show();

                            $('#inputPassword').nextAll('.colorRed').text('两次输入的密码不一样~！').show();

                            $('#inputPassword2').nextAll('.userMsg').show();

                            $('#inputPassword2').nextAll('.colorRed').text('两次输入的密码不一样~！').show();

                            return false;
                        }
                    }
                });
            }

            //加工昵称
            $('#email').on('input propertychange',function(){
                $('#nickname').val(hex_md5($(this).val()));
            });

        });
    </script>
</block>